package estyle.auto.nkornilova.applogicImp;

import estyle.auto.nkornilova.util.Browser;
import estyle.auto.nkornilova.util.PropertyLoader;
import estyle.auto.nkornilova.webdriver.WebDriverFactory;
import org.openqa.selenium.WebDriver;

public class ApplicationManager  {

    private UserHelper userHelper;
    private NavigationHelper navigateHelper;
    private BankAccountMessageGridHelper bankAccountMessageGridHelper;
    private BankAccountMessageHelper bankAccountMessageHelper;
    private WebDriver driver;
    private String baseUrl;

    public ApplicationManager() {
        baseUrl = PropertyLoader.loadProperty("site.url");
        String gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

        Browser browser = new Browser();
        browser.setName(PropertyLoader.loadProperty("browser.name"));
        browser.setVersion(PropertyLoader.loadProperty("browser.version"));
        browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

        String username = PropertyLoader.loadProperty("user.username");
        String password = PropertyLoader.loadProperty("user.password");

        driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, password);

        userHelper = new UserHelper(this);
        navigateHelper = new NavigationHelper(this);
        bankAccountMessageGridHelper = new BankAccountMessageGridHelper(this);
        bankAccountMessageHelper = new BankAccountMessageHelper(this);
    }

    protected WebDriver getWebDriver() {
        return driver;
    }

    protected String getBaseUrl() {
        return baseUrl;
    }

    public void stop() {
        if (driver != null) {
            driver.quit();
        }
    }

    public UserHelper getUserHelper() {
        return userHelper;
    }

    public NavigationHelper getNavigateHelper() {
        return navigateHelper;
    }

    public BankAccountMessageGridHelper getBankAccountMessageGridHelper() {
        return bankAccountMessageGridHelper;
    }

    public BankAccountMessageHelper getBankAccountMessageHelper() {
        return bankAccountMessageHelper;
    }
}
